package com.atguigu.flink.day03;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.RestOptions;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.LocalStreamEnvironment;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/8/12
 * 该案例演示了Flink执行环境的创建
 */
public class Flink01_Env {
    public static void main(String[] args) throws Exception {
        //创建本地执行环境
        //LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
        //创建本地执行环境  带WEBUI   需要添加flink-runtime-web依赖
        //StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());

        //创建远程执行环境
        StreamExecutionEnvironment env
                = StreamExecutionEnvironment.createRemoteEnvironment("hadoop102", 8081, "D:\\dev\\workspace\\bigdata-0318\\target\\bigdata-0318-1.0-SNAPSHOT.jar");


        //根据实际执行的场景自动创建远程或者本地执行环境
        //StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //注意：如果通过 StreamExecutionEnvironment.getExecutionEnvironment(conf)获取本地带WEBUI的执行环境
        //必须在conf中显式的执行WEBUI访问的端口号
        //Configuration conf = new Configuration();
        //conf.set(RestOptions.PORT,8088);
        //StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);

        DataStreamSource<String> ds = env.readTextFile("/opt/module/flink-1.17.0/words.txt");
        ds.print();
        env.execute();

    }
}
